package it.uniroma2.mpsr.resources;

import it.uniroma2.mpsr.utils.Misc;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;

public class State {
	private int[] configuration;
	private BigDecimal product;
	private double statProb;


	public State(int M) {
		this.configuration = new int[M];
		statProb = 0;
		product = BigDecimal.ONE;
	}

	public State(int[] n) {
		this.configuration = Arrays.copyOf(n, n.length);
		statProb = 0;
		product = BigDecimal.ONE;
	}

	public double getStatProb() {
		return statProb;
	}

	public void setStatProb(double statProb) {
		this.statProb = statProb;
	}

	public int[] getConfiguration() {
		return configuration;
	}

	public void setElement(int index, int value) {
		configuration[index] = value;
	}

	public int getElement(int index) {
		return configuration[index];
	}

	public void increment(int index) {
		configuration[index]++;
	}

	public void decrement(int index) {
		configuration[index]--;
	}

	
	public BigDecimal getProduct() {
		return product;
	}

	public void setProduct(double[] x, Centre[] centres) {
		for(int i = 0; i < configuration.length; i++) {
			product = product.multiply(
					BigDecimal.valueOf(x[i]).pow(configuration[i]).divide(
							new BigDecimal(Misc.betai(configuration[i], centres[i].getMultiplicity())), 20, RoundingMode.HALF_UP));
		}
	}

	@Override
	public String toString() {
		return Arrays.toString(configuration) + " " + statProb;
	}
}
